/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.jg.report.information.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 天津上报业务类型代码
 *
 * @author duanlikao
 * @created 2021/1/4
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum  BusinessTypeCodeEnum {
    /**
     * 干线普货运输服务
     */
    BUSINESS_TYPE_CODE_GXPHYS("1002996", "干线普货运输"),
    /**
     * 在城市范围内进行配送
     */
    BUSINESS_TYPE_CODE_CSPS("1003997", "城市配送"),
    /**
     * 若发货方或收货方在农村地区即为农村物流
     */
    BUSINESS_TYPE_CODE_NCPS("1003998", "农村配送"),
    BUSINESS_TYPE_CODE_JZXYS("1002998", "集装箱运输"),
    BUSINESS_TYPE_CODE_OTHER("1003999", "其他"),
    ;

    private  String code;
    private  String msg;

    private static Map <String, BusinessTypeCodeEnum> codeMap = Maps.newHashMap();


    public String getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public static String getMsg(String code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(String code) {
        return codeMap.containsKey(code);
    }

    static {
        for (BusinessTypeCodeEnum status : BusinessTypeCodeEnum
                .values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static BusinessTypeCodeEnum getBusinessTypeCodeEnumByVal(String code) {
        return Arrays.stream(BusinessTypeCodeEnum.values())
                .collect(Collectors.toMap(
                        BusinessTypeCodeEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }
}